package com.aliware.tianchi;



import org.apache.dubbo.rpc.Invoker;
import java.util.Map;
import java.util.concurrent.*;

public class GatewayManager  {
    public static final Map<String, ProviderInfo> LOAD_INFO = new ConcurrentHashMap<>();
    public static final Integer BUCKETNUM = 7;
    public static ProviderInfo getProviderInfo(Invoker<?> invoker) {
        String address = invoker.getUrl().getAddress();
        return LOAD_INFO.get(address);
    }
    public static void updateProviderInfo(String address, int avgTime, int activateCount, long avgTimeDuringSecond, int len, long [] c) {
        ProviderInfo providerInfo = LOAD_INFO.get(address);
        if (providerInfo == null) {
            providerInfo = new ProviderInfo();
            LOAD_INFO.put(address, providerInfo);
        }
        providerInfo.getAllReqCount().set(activateCount);
        providerInfo.setAvgSpendTime(avgTime);
        providerInfo.setLen(len);
        providerInfo.setAvgSpendDuringSecond(avgTimeDuringSecond);
        for (int i = 0; i < 7; i++) {
            if (c[i] == -1) {
                continue;
            }
            providerInfo.getCount().set(i, c[i]);
        }
    }

}
